<extend name="Layout:layout_edit" />
<block name="body_content_block">
    <form action="{:AddonU('Task/generate_numberq_save')}" method="post" id="frmMain">
        <div id="contents">
            <table>
                <script type="text/javascript">
                    for (i = 0; i < 10; i++) {
                        document.write('<tr><th>开始号码：</th><td><input type="text" name="startNo[]" placeholder="开始号码(手机11位,固话不限)" size="16" required onblur="startNo_Blur(this)"><a href="#" onclick="lnkStartNo_Click(this)">[选择]</a><span class="startNoTip"></span> 号码数量 <input type="text" name="endNo[]" placeholder="结束号码" size="8" value="1000" required onblur="endNo_Blur(this)" /> <a href="#" onclick="return lnkPlus_Click(this)" title="增加新任务">[+]</a><a href="#" onclick="return lnkMinus_Click(this)" title="删除此任务">[-]</a><span class="endNoTip"></span><input type="hidden" name="lastNo[]" /></td></tr>');
                    }
                    </script>
            </table><br />
            &nbsp;生成方式：<input type="radio" name="rule" value="order" />顺序生成 <input type="radio" name="rule" value="random" checked="checked" />乱序生成
        </div>
        <input type="hidden" name="taskStrategyID" value="{$tsid}"/>
    </form>
    <input type="hidden" id="pagnop_url" value="{:AddonU('Task/startno_picker')}" />
</block>
<block name="body_after_block">
    <script>
        item_form.resize_owner_dialog({width:520});
        // 2015-1-31 by sutroon
        function lnkPlus_Click(o) {
            var txt = '<tr><th>开始号码：</th><td> <input type="text" name="startNo[]" placeholder="开始号码(手机11位,固话不限)" size="16" required onblur="startNo_Blur(this)"><a href="#" onclick="lnkStartNo_Click(this)">[选择]</a><span class="startNoTip"></span> 号码数量 <input type="text" name="endNo[]" placeholder="结束号码" size="8" value="1000" required> <a href="#" onclick="return lnkPlus_Click(this)" title="增加新任务">[+]</a><a href="#" onclick="return lnkMinus_Click(this)" title="删除此任务">[-]</a><span class="endNoTip"></span><input type="hidden" name="lastNo[]" /></td></tr>';
            $(o).parent().parent().after(txt);
            return false;
        }
        function lnkMinus_Click(o) {
            $(o).parent().parent().remove();
            return false;
        }
        function startNo_Blur(o) {
            var val = $(o).val();
            if(!val){
                return;
            }
            var len = val.length;
            $(o).parent().find('.startNoTip').text('(' + len + '位)');
            getLastNo(o);
        }
        function endNo_Blur(o) {
            var val = $(o).val();
            if (!val) {
                return;
            }
            if (val * 1 > 1000) {
                $(o).val(1000);
                return;
            }
            getLastNo(o);
        }
        // 设置最后号码 2015-2-3 by sutroon
        function getLastNo(o) {
            var $li = $(o).parent().parent();
            var startNo = $li.find('input[name="startNo[]"]').val();
            var endNo = $li.find('input[name="endNo[]"]').val();
            if (!startNo || !endNo) {
                $li.find('input[name="lastNo[]"]').val('');
                $li.find('.endNoTip').text('');
                return;
            }
            if (startNo.length > endNo.length) {
                var a = startNo.substring(startNo.length - endNo.length - 1);
                startNo = startNo.substring(0, startNo.length - endNo.length - 1) + (a * 1 + endNo * 1);
            } else {
                startNo = startNo * 1 + endNo * 1;
            }
            $li.find('input[name="lastNo[]"]').val(startNo);
            $li.find('.endNoTip').text(startNo);
        }
    </script>
</block>